<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>列表</title>
    <link href="__STATIC__/component/pear/css/pear.css" rel="stylesheet"/>
    {include file='public/head.html'}
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-add="{:check_auth('add')}"
               data-auth-edit="{:check_auth('edit')}"
               data-auth-delete="{:check_auth('del')}"
               data-auth-modify="{:check_auth('multi')}"
               data-auth-remove="{:check_auth('remove_avatar')}"
        ></table>
    </div>
</div>

<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
    layui.use(['aphpTable', 'aphp'], function () {
        var aphpTable = layui.aphpTable;
        var aphp = layui.aphp;
        var $ = layui.$;
        var groupList = {:select_list(widget('admin_group')->get('all'))};

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('add')}",
            edit_url: "{:url('edit')}",
            delete_url: "{:url('del')}",
            modify_url: "{:url('multi')}",
        };

        aphpTable.render({
            init: init,
            url: "{:url('index')}",
            toolbar: ['refresh_table', 'add', 'enable', 'disable', 'delete'],
            search: true, //顶部搜索
            quickSearch: 'username@like#搜索账户', // 快速搜索设置
            cols: [
                [
                    { type: 'checkbox'},
                    { title: 'ID', field: 'id' },
                    { title: '角色组', field: 'group_id', templet:  aphpTable.formatter.flag, selectList: groupList },
                    { title: '账户', field: 'username', searchOp: 'like'},
                    { title: '昵称', field: 'nickname', searchOp: 'like'},
                    { title: '头像', field: '_avatar', search: false, templet:function (d) { return '<i><img width="25" height="25" alt="avatar" src=" '+d._avatar+'?'+Math.random()+'"></i>'; }},
                    { title: 'QQ号', field: 'qq', searchOp: 'like'},
                    { title: '手机', field: 'mobile', searchOp: 'like'},
                    { title: '登录次数', field: 'login_count', search: false},
                    { title: '登录时间', field: 'login_time' ,templet: aphpTable.formatter.datetime, search: 'range' },
                    { title: '创建时间', field: 'create_time' ,templet: aphpTable.formatter.datetime, search: 'range' },
                    { title: '状态', field: 'status', templet: aphpTable.formatter.switch},
                    { title: '操作', width:160, templet: function (d){
                            if(d.id===1){
                                return '<a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>';
                            }else{
                                return aphpTable.formatter.tool.call(this,d,this);
                            }
                        },operat: ['edit',
                            [{
                                title: '删除头像',
                                text: '',
                                class: 'layui-btn layui-btn-sm',
                                icon: 'layui-icon layui-icon-face-cry',
                                url: "{:url('remove_avatar')}",
                                method: 'request',
                                auth: 'remove',
                                confirm: true,
                            }],'delete']}
                ]
            ],
            page: {}
        });
        aphpTable.bindEvent();
    })
</script>
</body>
</html>